package com.alibaba.algo.domain.app;

import cn.hutool.core.lang.UUID;
import cn.hutool.crypto.SmUtil;
import com.alibaba.algo.core.base.BaseDomain;
import com.alibaba.algo.dao.app.AppAccountMapper;
import com.alibaba.algo.entity.app.AppAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 类AppAccount.java的实现描述：应用账号Domain
 *
 * @author nieganggang 2021-03-12 16:08:17
 */
@Component
public class AppAccountDomain extends BaseDomain<AppAccount> {

    @Autowired
    private AppAccountMapper appAccountMapper;

    /**
     * 新增应用账号
     *
     * @return 应用账号
     */
    public AppAccount add() {
        AppAccount appAccount = new AppAccount();
        // 生成appKey和appSecret
        String appKey = UUID.fastUUID().toString().replaceAll("-", "");
        String appSecret = SmUtil.sm3(appKey);
        appAccount.setAppKey(appKey);
        appAccount.setAppSecret(appSecret);
        appAccountMapper.insert(appAccount);
        return appAccount;
    }
}
